home *** CD-ROM | disk | FTP | other *** search
- ;void wrap_input(row,left_col,right_col,color,max_len,return_string);
- ; unsigned short row,left_col,right_col,color,max_len;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
- EXTRN _beep_on:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _wrap_input
- _wrap_input proc near
- push bp ;
- mov bp,sp ;set up stack frame
- push di ;
- push si ;
- mov _error_code,1 ;1 = parameter out of range
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- les di,dword ptr[bp+14] ;get ptr to return string
- jmp short L00 ;
- L0: mov ax,ds ;ES = DS
- mov es,ax ;
- mov di,[bp+14] ;
- L00: sub al,al ;clear AL
- mov es:[di],al ;return null if error
- mov ah,[bp+12] ;AH=maximum string len
- or ah,ah ;test if AH=0
- jnz B1 ;jump ahead if not
- A1: jmp Z1 ;quit routine if null str
- B1: sub al,al ;AL=initial string len
- mov si,ax ;store 2 values in SI
- sub bh,bh ;page 0
- mov bl,[bp+10] ;attribute byte in BL
- mov cl,[bp+8] ;right column in CL
- mov ch,[bp+6] ;left column in CH
- cmp cl,ch ;compare the two cols
- jna A1 ;quit if right not > left
- dec cl ;count right col from 0
- cmp cl,79 ;in range?
- ja A1 ;quit if not
- dec ch ;count left col from 0
- cmp ch,79 ;in range?
- ja A1 ;quit if not
- mov ah,[bp+4] ;starting row in AH
- dec ah ;count rows from 0
- cmp ah,24 ;in range?
- ja A1 ;quit if not
- dec _error_code ;0 = no error
- mov al,0FFH ;flg last spc chr,FF=none
- mov bp,di ;let BP point to return strg
- mov di,ax ;store 'lastspc' in DI
- mov dh,ah ;current cursor row in DH
- mov dl,ch ;current cursor col in DL
- mov ah,2 ;function to set cursor
- int 10h ;set initial cursor
- C1: sub ah,ah ;func to read keystroke
- int 16h ;wait for a keystroke
- or al,al ;extended code?
- jnz D1 ;jump ahead if not
- int 16h ;clear 2nd byte of code
- jmp short C1 ;go get next keystroke
- D1: cmp al,8 ;is it the backspace?
- jne E1 ;jump ahead if not
- jmp Q1 ;jump to bkspc routine
- E1: cmp al,13 ;is it a carriage return?
- jne F1 ;jump ahead if not
- jmp Z1 ;go quit the routine
- F1: cmp al,27 ;is it escape?
- jne G1 ;jump ahead if not
- sub al,al ;ready to set null string
- mov es:[bp],al ;set return str to null
- jmp Z1 ;go quit the routine
- G1: cmp al,32 ;an other char < 32?
- jb C1 ;reject it if so
- xchg ax,si ;get string length ctr
- cmp al,ah ;equal to maxlen?
- jne I1 ;jump ahead if not
- xchg ax,si ;return ctr to SI
- H1: push dx ;get ready to beep
- mov ah,2 ;DOS screen write func
- mov dl,7 ;bell character
- cmp _beep_on,0 ;see if beep is enabled
- jz H2 ;jump ahead if not
- int 21h ;beep!
- H2: pop dx ;restore DX
- jmp short C1 ;go wait for next char
- I1: inc al ;increment counter
- xchg ax,si ;send back to SI
- cmp al,32 ;test for spc char
- jne J1 ;jump if not spc char
- xchg ax,di ;swap 'lastspc' to AL
- mov al,dl ;current col to AL
- xchg ax,di ;swap back to DI
- J1: push cx ;save CX contents
- push si ;SI changed below
- mov ah,1 ;increment for str length
- add es:[bp],ah ;increment the length
- sub cx,cx ;clear CX
- mov cl,es:[bp] ;str len to CX
- mov si,cx ;move to SI
- mov es:[bp][si],al ;set the character
- pop si ;restore SI
- mov cx,1 ;number chars to write
- mov ah,9 ;function to write char
- int 10h ;write the char
- pop cx ;restore CX
- cmp cl,dl ;end of line position?
- jne O1 ;jump ahead if not
- cmp al,32 ;is end of line a spc?
- je N1 ;no wrap, go print it
- mov ax,di ;get 'prior spc' ptr
- cmp al,0ffh ;test for any spaces
- jne K1 ;jump ahead if found
- jmp N1 ;else don't wrap
- K1: push di ;DI changed
- mov ah,dh ;save row in AH
- inc dh ;point to next row
- mov dl,ch ;point to left col
- xchg dx,di ;now DL=col of prior spc
- mov dh,ah ;current row to DH
- inc dl ;prior spc col + 1
- L1: mov ah,2 ;func to set cursor
- int 10h ;set the cursor
- mov ah,8 ;func reads char at curs
- int 10h ;char to AL
- push cx ;save left/right col vals
- push ax ;save keystroke in AL
- mov al,0FFH ;erase eol with FF char
- mov ah,9 ;function to write char
- mov cx,1 ;number chars to write
- int 10h ;erase end-of-line char
- xchg dx,di ;cursor pos below to DX
- mov ah,2 ;function to set cursor
- int 10h ;set cursor to below
- pop ax ;restore char to AL
- mov ah,9 ;function to write char
- mov cx,1 ;number chars to write
- int 10h ;write the char in AL
- pop cx ;restore CX
- inc dl ;set col position forward
- xchg dx,di ;return cursor pos above
- cmp dl,cl ;end of line?
- je M1 ;jump ahead if so
- inc dl ;col plus one
- jmp short L1 ;go transfer next char
- M1: xchg dx,di ;return cursor pos below
- mov ah,2 ;function to set cursor
- int 10h ;set the cursor
- pop ax ;restore DI to AX
- mov al,0ffh ;reset 'prior spc' ptr
- mov di,ax ;now place in DI
- jmp C1 ;go get next char
- N1: inc dh ;cursor to next row
- mov dl,ch ;cursor to left col
- mov ax,di ;get 'prior spc' ptr
- mov al,0ffh ;reset to FF
- mov di,ax ;return it to DI
- jmp short P1 ;jump ahead
- O1: inc dl ;cursor to next col
- P1: mov ah,2 ;function to set cursor
- int 10h ;set the cursor
- jmp C1 ;go get next keystroke
- Q1: cmp dl,ch ;BACKSPACE: left col?
- jne X1 ;jump ahead if not
- mov ax,di ;now AH has start row
- cmp dh,ah ;same as current row?
- jne R1 ;jump ahead if not
- jmp H1 ;else go beep
- R1: dec dh ;dec row ptr
- mov dl,cl ;left col position
- S1: mov ah,2 ;func to set cursor
- int 10h ;set the cursor
- mov ah,8 ;func to read char
- int 10h ;read char at cursor
- cmp al,0FFH ;is it a fill char?
- jne T1 ;jump ahead if not
- dec dl ;dec col position
- jmp short S1 ;chk next char to left
- T1: push dx ;seek "last space" pos
- U1: dec dl ;dec cursor col
- cmp dl,ch ;left margin?
- jnb V1 ;jump ahead if not
- mov ah,0ffh ;else no space on line
- jmp short W1 ;jump ahead
- V1: mov ah,2 ;function to set cursor
- int 10h ;set the cursor
- mov ah,8 ;function to fetch char
- int 10h ;get char at position
- cmp al,32 ;is it a space?
- jne U1 ;loop if not
- mov ah,dl ;else save pos in AH
- W1: mov dx,di ;"last space" in DI (low)
- mov dl,ah ;set new "last space"
- mov di,dx ;replace in DI
- pop dx ;restore current curs pos
- mov ah,2 ;func to set cursor
- int 10h ;reset current cursor
- jmp short Y1 ;jump, continue backspc
- X1: dec dl ;decrement col ptr
- mov ah,2 ;function to set cursor
- int 10h ;set the cursor
- jmp short T1 ;reset "last space"
- Y1: mov al,' ' ;use spc char to erase
- mov ah,9 ;function to write char
- push cx ;must change CX
- mov cx,1 ;number chars to write
- int 10h ;write the space char
- pop cx ;restore CX
- mov ah,es:[bp] ;get ret str descriptor
- dec ah ;decrement it
- mov es:[bp],ah ;replace
- xchg si,ax ;get string len ctr
- dec al ;decrement it
- xchg si,ax ;replace
- jmp C1 ;go get next keystroke
- Z1: sub cx,cx ;change to C string
- mov cl,es:[bp] ;get string length
- jcxz B2 ;quit if null
- A2: inc bp ;
- mov al,es:[bp] ;
- mov es:[bp-1],al ;
- loop A2 ;
- mov byte ptr es:[bp],0 ;null terminator
- B2: pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _wrap_input ENDP
- _TEXT ENDS
- END